package gateway

import (
	"context"
	"server/component"
	"server/im/entity"
	"sync"
)

type GateWay interface {
	Start(wg *sync.WaitGroup)
	Stop()
	GetUniId() string
	GetClientChan() chan entity.GatewayClientEvent
	GetGatewayInputChan() chan entity.GatewayInModel
	GetGatewayOutputChan() chan entity.GatewayOutModel

	GetCoreInputChan() chan entity.CoreInModel
	GetCoreOutputChan() chan entity.CoreOutModel
}

type GateWayConn interface {
	CloseFn()
	//ReadFn(exitChan <-chan struct{}) (entity.GatewayInModel, error)
	DoRead(readChan chan entity.GatewayInModel, errChan chan error, stopChan chan struct{})
	WriteFn(writeModel entity.GatewayOutModel)
	GetGateWay() GateWay
}

func NewGateway(ctx context.Context, imConfig component.ImServerConfig) GateWay {
	var imGateway GateWay
	if imConfig.Type == "tcp" {
		imGateway = NewTcpSocketServer(
			ctx,
			imConfig)
	} else if imConfig.Type == "websocket" {
		imGateway = NewWebSocketServer(
			ctx,
			imConfig,
		)
	}
	return imGateway
}
